package cn.wolfcode.trip.app.web.controller;

import cn.wolfcode.trip.app.util.UserContext;
import cn.wolfcode.trip.base.domain.Daily;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.query.DailyQueryObject;
import cn.wolfcode.trip.base.query.TravelQuery;
import cn.wolfcode.trip.base.service.IDailyService;
import cn.wolfcode.trip.base.service.ITravelService;
import cn.wolfcode.trip.base.service.IUserService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@RequestMapping("/dailies")
@Controller
public class DailyController {
    @Autowired
    private IDailyService dailyService;

    @GetMapping
    @ResponseBody
    public Object query(DailyQueryObject qo){
        PageInfo pageInfo = dailyService.query(qo);
        return pageInfo;
    }

    //用户收藏的日报
    @GetMapping("/collection")
    @ResponseBody
    public Object queryCollection(DailyQueryObject qo){
        PageInfo pageInfo = dailyService.queryCollection(qo);
        return pageInfo;
    }

    @GetMapping("/saveOrDeleteCollection")
    @ResponseBody
    public Object saveOrDeleteCollection(Long userId,Long dailyId){
        JSONResult result = dailyService.saveOrDeleteCollection(userId, dailyId);
        return result;
    }

    @GetMapping("/selectCollectionByUserId")
    @ResponseBody
    public Object selectCollectionByUserId(Long userId){
        List<Long> ids = dailyService.selectCollectionByUserId(userId);
        return ids;
    }

    @GetMapping("/{id}")
    @ResponseBody
    public Object get(@PathVariable Long id){
        return dailyService.get(id);
    }
}
